package mest.controller.Modeling;

import com.alibaba.fastjson.JSON;
import mest.entity.customer_file;
import mest.entity.customer_type;
import mest.service.Modeling.ICustomerFileService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @auther Machenike
 * @create 2019-11-14 15:24
 */
//Model是属于请求域
//           @RequestMapping(value="/one",params = "method=a")
//           @RequestMapping(value="/two1",produces = {"application/json;charset=utf-8","text/plain;charset=utf-8"})
//参数:@RequestParam(value = "b",required = false,defaultValue = "握草尼玛")
//         @RequestBody String(str) 输出:userCode=admin&userPassword=1234567
//          @SessionAttributes({"a","b","c"}) 自动把该controller下所有返回页面的属性的作用域改成session
//          @ModelAttribute标注一个方法时，指定每次跳入某个路径时该方法先执行
@RestController
@CrossOrigin
@RequestMapping(value = "/CustomerFile")
public class CustomerFile {


    @Resource
    private ICustomerFileService icfs;

    @RequestMapping(value="/insert")
    public String insert(customer_file cf ){
        int i = icfs.insertCustomerFile(cf);
        if (i >= 1)
            return JSON.toJSONString("添加成功");
        else
            return JSON.toJSONString("添加失败");
    }
    @RequestMapping(value = "/baseSelect", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public String baseSelect(int index,int pageSize) {

        List<customer_file> customerFilePage = icfs.findCustomerFilePage(index, pageSize);
        int i = icfs.selectCount();
        Map map  = new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",i);
        map.put("data",customerFilePage);
        return JSON.toJSONString(map);
    }

}
